package com.antler.smt.portal.service.impl;

import com.antler.smt.entity.HiringEntity;
import com.antler.smt.enums.ResultCodeEnum;
import com.antler.smt.portal.mapper.HiringEntityMapper;
import com.antler.smt.portal.mapper.HiringInfoMapper;
import com.antler.smt.request.portal.HiringReq;
import com.antler.smt.response.base.Result;
import com.antler.smt.service.portal.HiringService;
import com.antler.smt.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author zhangyi
 * @date 2018/9/19 10:03
 */
@Service
public class HiringServiceImpl implements HiringService {

    @Autowired
    private HiringEntityMapper hiringEntityMapper;

    @Autowired
    private HiringInfoMapper hiringInfoMapper;

    /**
     * 插入招人信息
     *
     * @param hiringReq
     * @return
     */
    @Override
    public Result insertHiring(HiringReq hiringReq,Long memberId) {
        HiringEntity hiringEntity = new HiringEntity();
        hiringEntity.setMemberId(memberId);
        hiringEntity.setCompanyName(hiringReq.getCompanyName());
        hiringEntity.setCompanyProfile(hiringReq.getCompanyProfile());
        hiringEntity.setCompanyScale(hiringReq.getCompanyScale());
        hiringEntity.setMainDirection(hiringReq.getMainDirection());
        hiringEntity.setProductDescription(hiringReq.getProductDescription());
        //创建时间
        hiringEntity.setCreateTime(DateUtil.stampToDate(System.currentTimeMillis()));

        int i = hiringEntityMapper.insertSelective(hiringEntity);

        return (0 == i) ? new Result(ResultCodeEnum.APPEND_DATA_ERROR,"插入数据失败")
                : new Result(ResultCodeEnum.OPERATION_SUCCESS,"插入数据成功！");

    }

    /**
     * 获取招人信息
     *
     * @param memberId
     * @return
     */
    @Override
    public Result selectHiring(Long memberId) {
        HiringEntity hiringEntityResult =
                hiringInfoMapper.selectInfoByMemberId(memberId);
        return new Result(hiringEntityResult);
    }
}
